package com.vip.mvc.spring;

import com.vip.mvc.annotation.Controller;
import com.vip.mvc.annotation.Service;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Map;

/**
 * Created by cloudy.xie on 17/2/21.
 */
public class NaBeansFactory {

    private static  ApplicationContext controllerCtx = new ClassPathXmlApplicationContext("spring1.xml");
    private static  ApplicationContext serviceCtx = new ClassPathXmlApplicationContext("spring2.xml");

    public static Object getSerivceBean(String beanName) {
        return serviceCtx.getBean(beanName);
    }

    public static Object getControllerBean(String beanName) {
        return controllerCtx.getBean(beanName);
    }

    public static Map<String, Object> getSerivceBeans(){
        return serviceCtx.getBeansWithAnnotation(Service.class);
    }

    public static Map<String, Object> getControllerBeans(){
        return controllerCtx.getBeansWithAnnotation(Controller.class);
    }

}